<template>
  <div>
    <div>
      <title-go-back :title="title"></title-go-back>
    </div>
    <div class="house_map_content">
      <baidu-map class="bm-view" ak="lxCGtxzYDf1rK69UBspuzmxYkuYH725Q"
                 :center="center" :zoom="zoom"
                 :scroll-wheel-zoom="true"
                 @ready="handler">
      </baidu-map>
    </div>
  </div>
</template>


<script>
  import BaiduMap from 'vue-baidu-map/components/map/Map.vue'
  import TitleGoBack from './TitleGoBack';
  import {getLatitude,getLongitude} from '../../assets/js/cache';
import {getCityMap} from '../../axios/api';

  export default {
    name:'HouseMap',
    data(){
      return{
        title:'地图找房',
        center: {lng: 0, lat: 0},
        zoom: 3,
        BMap: null,
        map: null,
        // latitude: '19.946464',
        // longitude: '110.119416',
        latitude: 0,
        longitude: 0,
        buildName:'当前位置'
      }
    },
    created(){
     this.latitude =  getLatitude();
     this.longitude =  getLongitude();
     console.log(getLatitude(),getLongitude());
    },
    methods:{
      handler({BMap, map}){
        if (getLatitude() !== undefined && getLongitude() !== undefined) {
          this.latitude =  getLatitude();
          this.longitude =  getLongitude();
        }else {
          // this.latitude =  '19.946464';
          // this.longitude =  '110.119416';
          this.latitude =  '20.0497739066';
          this.longitude =  '110.2048317258';
        }

        // window.alert(getLatitude());
        // window.alert(getLatitude());
        this.center.lng = this.longitude; //经度   x
        this.center.lat = this.latitude;  //纬度   y
        let markergg = new BMap.Marker(new BMap.Point(this.center.lng,this.center.lat));
        map.addOverlay(markergg); //添加GPS marker
        let labelgg = new BMap.Label(this.buildName,{offset:new BMap.Size(20,-10)});
        markergg.setLabel(labelgg); //添加GPS label
        this.zoom = 15; //搜索级别
        this.BMap = BMap;
        this.map = map;
        setTimeout(()=>{
          getCityMap(this.map.Yg).then(res=>{
          }).catch(err=>{
            console.log(err);
          })
        },1500);

      }
    },
    components: {
      TitleGoBack,
      BaiduMap
    },
  }
</script>
<style>
.house_map_content{
  /*margin-top: 50px;*/
}
  .bm-view{
    width: 100%;
    height: calc(100vh - 50px);
  }
</style>
